/*
  Copyright (c) 2010
  The Regents of the University of Michigan
  All Rights Reserved

  Permission is granted to use, copy, create derivative works, and
  redistribute this software and such derivative works for any purpose,
  so long as the name of the University of Michigan is not used in
  any advertising or publicity pertaining to the use or distribution
  of this software without specific, written prior authorization. If
  the above copyright notice or any other identification of the
  University of Michigan is included in any copy of any portion of
  this software, then the disclaimer below must also be included.

  This software is provided as is, without representation or warranty
  of any kind either express or implied, including without limitation
  the implied warranties of merchantability, fitness for a particular
  purpose, or noninfringement.  The Regents of the University of
  Michigan shall not be liable for any damages, including special,
  indirect, incidental, or consequential damages, with respect to any
  claim arising out of or in connection with the use of the software,
  even if it has been or is hereafter advised of the possibility of
  such damages.
*/
/* Created by Dhritiman Sagar. */
#ifndef MOJITO_TYPES_H
#define MOJITO_TYPES_H

#include <sys/types.h>
#include <netinet/in.h>
#include <glib.h>

#include "mojito_constants.h"

enum Action {
	ACT_REQUEST_PING = 0x01,
	ACT_REPLY_PING = 0x02,
	ACT_REQUEST_STORE = 0x03,
	ACT_REPLY_STORE = 0x04,
	ACT_REQUEST_FIND_NODE = 0x05,
	ACT_REPLY_FIND_NODE = 0x06,
	ACT_REQUEST_FIND_VALUE = 0x07,
	ACT_REPLY_FIND_VALUE = 0x08,
	ACT_STATS_REQUEST = 0x09, //Deprecated
	ACT_STATS_RESPONSE = 0x0A, //Deprecated
};


struct StatusCode{
	uint16_t status_code; /*The status code*/
	uint16_t len;
	char* descript; /*UTF-8 encoded string describing the status_code*/
};

enum StatusCodeValues{
  OK = 0x01,
  ERROR = 0x02,
};




typedef uint32_t vendor_type_t; /*Usually 'LIME'*/

typedef uint16_t version_t; /*Byte 0 is the Major version, Byte 1 is the Minor version */


struct kuid_t {
	/* length assumed to be KUID_SIZE always */
	uint8_t bytes[KUID_SIZE];  /* stored big-endian. */
};



struct SocketAddress {
	uint8_t len;
	struct in_addr addr; /*Stored in network byte order*/
	uint16_t port;      /*Stored in network byte order*/
};


//Wrapper around long long (TODO: Remove if not needed)
struct BigInteger{
	uint8_t len;
	uint32_t val;
};


struct SecurityToken{
	uint8_t len;
	char* sec_token;
};



struct Contact{ /*Holds information needed to contact a node*/
	vendor_type_t vendor;
	version_t version; /*Version of the contact. 4 for IPV4*/
	struct kuid_t kuid;
	struct SocketAddress sock_addr;
};


typedef uint32_t dht_value_type_t;

//Types of DHT values
enum DHTValueType {
	BINARY = 0x00000000, /*Arbitrary binary value*/
	LIME = 0x4c494d45,   /*LIME and all derivations of LIME (resevred for Limewire)*/
	TEXT = 0x54455854,   /*A text based value*/
	ANY = 0x2a2a2a2a,    /*Used for requesting. Can't be used as an actual value type.*/
	TEST = 0X54455354,   /*Like BINARY. Used for testing*/
};

struct DHTValue {
	struct Contact contact;        /*Creator's IPv4 address*/
	struct kuid_t kuid;          /*The key of the DHTValue*/
	dht_value_type_t value_type;   /*The type of the value as defined above*/
	version_t version;             
	uint16_t len;                 /*The length of the DHTValue*/
	char* value_bytes;              /*The actual value*/
};

#endif
